package net.yxsoft.service;

import com.jfinal.aop.Inject;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import io.undertow.server.handlers.form.FormData;
import net.yxsoft.enumclass.WhetherEnumCls;
import net.yxsoft.kit.Helper;
import net.yxsoft.model.*;
import net.yxsoft.model.formdesigner.FnFormData;
import net.yxsoft.model.infrastructure.TsCode;
import net.yxsoft.model.infrastructure.TsMenu;
import net.yxsoft.service.common.BaseService;
import net.yxsoft.service.formdisigner.FormDataRoleService;
import net.yxsoft.service.formdisigner.FormDataService;
import org.apache.commons.lang.StringUtils;
import rapid.core.Authuser;
import rapid.core.ContextStateEnum;
import rapid.core.TResult;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 描述：生命周期实例
 * @author 彭涛涛
 * 时间：2019年6月24日
 */
public class LifecycExampleService extends BaseService {
  public static final LifecycExampleService me = new LifecycExampleService();
  private SLifecycExample exampleDao = new SLifecycExample().dao();
  private SLifecycExampleNode exampleNodeDao = new SLifecycExampleNode().dao();
  private SLifecycExampleNodePer exampleNodePerDao = new SLifecycExampleNodePer().dao();
  private SLifecycModel modelDao = new SLifecycModel().dao();
  private SLifecycModelNode modelNodeDao = new SLifecycModelNode().dao();
  private TsCode codeDao = new TsCode().dao();


  public static final FormDataService rsv = new FormDataService();

  /**
  * @MethodName: getLifecycModel
  * @Description: 获取生命周期模型
  * @param: modelName
  * @return * @return java.util.List<com.jfinal.plugin.activerecord.Record>
  * @throws
  * @date 2023/8/31 15:49
  * @author wj
  */
  public List<Record> getLifecycModel(String modelName) {
    StringBuilder _strSql = new StringBuilder();
    StringBuilder _strWhere = new StringBuilder();
    _strSql.append("select conflict_id,attrib_01 from s_lifecyc_model where attrib_15 = '1' ");
    if(StrKit.notBlank(modelName)) {
      _strWhere.append(Helper.getVagueQuery(modelName, " attrib_01 ", true));
    }
    List<Record> _returnData = new ArrayList<Record>();
    String resultSql = _strSql.toString() + _strWhere.toString() + " order by attrib_01 desc limit 20";
    _returnData = Db.find(resultSql);
    return _returnData;
  }

  /**
  * @MethodName: getLifecycModelById
  * @Description: 获取生命周期模型根据id
  * @param: conflictId
  * @return * @return net.yxsoft.model.SLifecycModel
  * @throws
  * @date 2023/8/31 15:49
  * @author wj
  */
  public SLifecycModel getLifecycModelById(String conflictId) {
    return modelDao.findById(conflictId);
  }


  /**
  * @MethodName: saveLifecycExample
  * @Description: 保存生命周期实例
  * @param: model
   * @param: pid
   * @param: menuCode
   * @param: loginUser
  * @return * @return rapid.core.TResult
  * @throws
  * @date 2023/8/31 15:49
  * @author wj
  */
  public TResult saveLifecycExample(SLifecycExample model,String pid,String menuCode, Authuser loginUser) {
    if(StrKit.notNull(loginUser)) {
      Date date = new Date(System.currentTimeMillis());
      String Logs = "";
      List<String> _sqlList = new ArrayList<>();
      SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      if(StrKit.isBlank(model.getConflictId())) {
        String exampleId = Helper.bulidUUID();
        Record isExist = Db.findFirst("select conflict_id,attrib_01 from s_lifecyc_example \n" +
                                        " where attrib_01=? or attrib_03=? ", model.getAttrib01(),model.getAttrib03());
        if(null == isExist) {
//          Record recordModel = Db.findFirst(" select * from s_lifecyc_model where conflict_id =?",model.getRowId());
          String rq1="";
          if(model.getAttrib14()!=null) {
             rq1 = "str_to_date('" + df.format(model.getAttrib14()) + "','%Y-%m-%d %H:%i:%s')";
          }else {
            rq1="null";
          }
          String sql1=" insert into s_lifecyc_example(conflict_id,row_id,attrib_01,attrib_02,attrib_03,attrib_04,attrib_05,attrib_14,attrib_15,attrib_19,created_by,attrib_16,attrib_21) " +
                          " values('"+exampleId+"','"+model.getRowId()+"','"+model.getAttrib01()+"','"+ model.getAttrib02()+"','"+model.getAttrib03()+"','"+model.getAttrib04()+"','"+model.getAttrib05()+"',"+rq1+",'"+ model.getAttrib15()+"','"+model.getAttrib19()+"','"+loginUser.getName()+"','0','"+model.getAttrib21()+"')";

          _sqlList.add(sql1);
          List<Record> nodeList = Db.find(" select * from s_lifecyc_model_node where attrib_15 ='1' and row_id =? ", model.getRowId());
          for(Record record : nodeList) {
            String exampleNodeId = Helper.bulidUUID();

            String rq="";
            if(model.getAttrib14()!=null) {
              rq = "str_to_date('"+df.format(model.getAttrib14())+"','%Y-%m-%d %H:%i:%s')";
            }else {
              rq="null";
            }
            String sql=" insert into s_lifecyc_example_node(conflict_id,row_id,attrib_01,attrib_02,attrib_11,attrib_12,attrib_13,attrib_21,attrib_14)" +
                            " values('"+exampleNodeId+"','"+exampleId+"','"+record.getStr("attrib_01")+"','"+record.getStr("conflict_id")+"',"+record.get("attrib_11")+",'"+record.getStr("attrib_12")+"','"+record.getStr("attrib_13")+"',"+"'"+record.getStr("attrib_20")+"',"+rq+")";


            _sqlList.add(sql);
            List<Record> accList = Db.find(" select * from s_lifecyc_model_node_acc where row_id =? ", record.getStr("conflict_id"));
            for(Record accRecord : accList) {
              _sqlList.add(String.format(" insert into s_lifecyc_example_node_acc(conflict_id,row_id,attrib_01,attrib_15) " +
                                         " values('%s','%s','%s','%s')", Helper.bulidUUID(),
                                         exampleNodeId, accRecord.getStr("attrib_01"), accRecord.getStr("attrib_15")));
            }
          }
          Logs = "主键:" + exampleId + "标题：" + model.getAttrib01() + ";编号："+model.getAttrib03();
          log(loginUser.getId(), loginUser.getName(), "生命周期/生命周期实例", "新增", loginUser.getIp(), Logs);
        } else {
          String msg ="";
          if(model.getAttrib01().equals(isExist.getStr("attrib_01"))){
            msg = "您输入的生命周期实例标题已存在！";
          }else {
            msg = "您输入的生命周期实例编号已存在！";
          }
          return TResult.fail(msg);
        }
      } else {
        SLifecycExample exmapleOject = exampleDao.findById(model.getConflictId());
        if(null != exmapleOject) {
          Record isExist = Db.findFirst("select conflict_id,attrib_01 from s_lifecyc_example \n" +
                                          " where (attrib_01=? or attrib_03=?) and conflict_id<>? ", model.getAttrib01(),model.getAttrib03(), model.getConflictId());
          Logs = "主键:" + exmapleOject.getConflictId() +
            ";修改前标题：" + exmapleOject.getAttrib01() + ";修改后标题：" + model.getAttrib01() +
            ";修改前有效截止日期：" + exmapleOject.getAttrib14() + ";修改后有效截止日期：" + model.getAttrib14() +
            ";修改前状态：" + exmapleOject.getAttrib15() + "(0：禁用;1：启用);修改后状态：" + model.getAttrib15() + "(0：禁用;1：启用)" +
                  ";修改前是否结束状态：" + exmapleOject.getAttrib16() + "(1：未结束;0：已结束);修改后是否结束状态：" + model.getAttrib16() + "(1：未结束;0：已结束)" +
            ";修改前编号：" + exmapleOject.getAttrib03() + ";修改后编号：" + model.getAttrib03() ;
          if(null == isExist) {
            exmapleOject.setLastUpd(date);
            exmapleOject.setLastUpdBy(loginUser.getName());
            exmapleOject.setAttrib01(model.getAttrib01());
            exmapleOject.setAttrib03(model.getAttrib03());
            exmapleOject.setAttrib04(model.getAttrib04());
            exmapleOject.setAttrib05(model.getAttrib05());
            exmapleOject.setAttrib14(model.getAttrib14());
            exmapleOject.setAttrib15(model.getAttrib15());
            exmapleOject.setAttrib19(model.getAttrib19());
            exmapleOject.setAttrib16(model.getAttrib16());
            exmapleOject.setAttrib21(model.getAttrib21());
            if(exmapleOject.update() != true) {
              return TResult.fail("编辑失败！");
            }
            log(loginUser.getId(), loginUser.getName(), "生命周期/生命周期实例", "编辑", loginUser.getIp(), Logs);
          } else {
            String msg ="";
            if(model.getAttrib01().equals(isExist.getStr("attrib_01"))){
              msg = "您输入的生命周期实例标题已存在！";
            }else {
              msg = "您输入的生命周期实例编号已存在！";
            }
            return TResult.fail(msg);

          }
        } else {
          return TResult.fail("您编辑的数据不存在或已被删除！");
        }
      }
      Db.batch(_sqlList, 10000);
      if(StrKit.notBlank(pid)) {
        TsMenu menu = new TsMenu();
        menu.setPid(Integer.parseInt(pid));
        TResult re = saveExampleMenu(menu, model.getAttrib01(), model.getAttrib03(), loginUser);
        if(re.isFail()){
          return TResult.fail(re.getMessage());
        }
      }

    } else {
      return TResult.fail("未获得用户信息,请重新登录！");
    }
    return success();
  }



  /**
  * @MethodName: saveLifecycExampledl
  * @Description: 保存生命周期实例（dl）
  * @param: model
   * @param: pid
   * @param: loginUser
   * @param: conid
   * @param: ptype
  * @return * @return rapid.core.TResult
  * @throws
  * @date 2023/8/31 15:49
  * @author wj
  */
  public TResult saveLifecycExampledl(SLifecycExample model,String pid, Authuser loginUser,String conid,String ptype){
    TResult result=new TResult();
    if(StrKit.notNull(loginUser)) {
      Date date = new Date(System.currentTimeMillis());
      String Logs = "";
      List<String> _sqlList = new ArrayList<>();
      SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

      String exampleId = Helper.bulidUUID();
      Record isExist = Db.findFirst("select conflict_id,attrib_01 from s_lifecyc_example \n" +
              " where attrib_01=? or attrib_03=? ", model.getAttrib01(),model.getAttrib03());

      if(null == isExist) {

        String rq1="str_to_date('"+df.format(model.getAttrib14())+"','%Y-%m-%d %H:%i:%s')";
        String sql1=" insert into s_lifecyc_example(conflict_id,row_id,attrib_01,attrib_02,attrib_03,attrib_04,attrib_05,attrib_14,attrib_15,attrib_19,created_by,attrib_16,attrib_21) " +
                " values('"+exampleId+"','"+model.getRowId()+"','"+model.getAttrib01()+"','"+ model.getAttrib02()+"','"+model.getAttrib03()+"','"+model.getAttrib04()+"','"+model.getAttrib05()+"',"+rq1+",'"+ model.getAttrib15()+"','"+model.getAttrib19()+"','"+loginUser.getName()+"','0','"+model.getAttrib21()+"')";

        _sqlList.add(sql1);
        List<Record> nodeList = Db.find("select * from s_lifecyc_model_node where attrib_15 ='1' and row_id =? ", model.getRowId());
        for(Record record : nodeList) {
          String exampleNodeId = Helper.bulidUUID();
          String rq="str_to_date('"+df.format(model.getAttrib14())+"','%Y-%m-%d %H:%i:%s'))";
          String sql=" insert into s_lifecyc_example_node(conflict_id,row_id,attrib_01,attrib_02,attrib_11,attrib_12,attrib_13,attrib_21,attrib_14)" +
                  " values('"+exampleNodeId+"','"+exampleId+"','"+record.getStr("attrib_01")+"','"+record.getStr("conflict_id")+"',"+record.get("attrib_11")+",'"+record.getStr("attrib_12")+"','"+record.getStr("attrib_13")+"',"+"'"+record.getStr("attrib_20")+"',"+rq;

          if(record.getStr("attrib_01").indexOf("项目登记")!=-1){
            SLifecycExampleNodePer modelpre= new SLifecycExampleNodePer();
            modelpre.setAttrib01(conid);
            modelpre.setAttrib02("PARTICIPATE");
            modelpre.setConflictId(null);
            modelpre.setRowId(exampleNodeId);
            saveLifecycExamplePER(modelpre,loginUser);
          }

          _sqlList.add(sql);
          List<Record> accList = Db.find(" select * from s_lifecyc_model_node_acc where row_id =? ", record.getStr("conflict_id"));
          for(Record accRecord : accList) {
            _sqlList.add(String.format(" insert into s_lifecyc_example_node_acc(conflict_id,row_id,attrib_01,attrib_15) " +
                            " values('%s','%s','%s','%s')", Helper.bulidUUID(),
                    exampleNodeId, accRecord.getStr("attrib_01"), accRecord.getStr("attrib_15")));
          }
        }
        Logs = "主键:" + exampleId + "标题：" + model.getAttrib01() + ";编号："+model.getAttrib03();
        log(loginUser.getId(), loginUser.getName(), "生命周期/生命周期实例", "新增", loginUser.getIp(), Logs);
      } else {
        String msg ="";
        if(model.getAttrib01().equals(isExist.getStr("attrib_01"))){
          msg = "您输入的生命周期实例标题已存在！";
        }else {
          msg = "您输入的生命周期实例编号已存在！";
        }
        result.setState(ContextStateEnum.FAIL);
        result.isFail();
        result.setMessage(msg);
        return result;
      }

      Db.batch(_sqlList, 10000);
      if(StrKit.notBlank(pid)) {
        TsMenu menu = new TsMenu();
        menu.setPid(Integer.parseInt(pid));
        TResult re = saveExampleMenu(menu, model.getAttrib01(), model.getAttrib03(), loginUser);
        if(re.isFail()){
          result.setState(ContextStateEnum.FAIL);
          result.isFail();
          result.setMessage("创建失败");
          return result;
        }
      }

    } else {
      result.setState(ContextStateEnum.FAIL);
      result.isFail();
      result.setMessage("未获得用户信息,请重新登录！");
      return result;
    }
    Record Exist = Db.findFirst("select conflict_id from s_lifecyc_example \n" +
            " where attrib_01=? and attrib_03=? ", model.getAttrib01(),model.getAttrib03());

    if(Exist!=null && StrKit.notBlank(Exist.getStr("conflict_id"))){
      Record Existnode = Db.findFirst("select conflict_id,attrib_12 from s_lifecyc_example_node \n" +
              " where row_id=? and attrib_11='1' ", Exist.getStr("conflict_id"));

      if(Existnode!=null &&  StrKit.notBlank(Existnode.getStr("conflict_id"))){

        FnFormData formData=new FnFormData();
        formData.setAttrib01(Existnode.getStr("attrib_12"));
        formData.setAttrib02(Existnode.get("conflict_id"));
        formData.setAttrib03(ptype);
        formData.setAttrib04(model.getAttrib03());
        formData.setAttrib05(model.getAttrib01());
        try {
          rsv.add(formData,loginUser,"0",null,null);
        } catch (ParseException e) {
          e.printStackTrace();
        }
      }

      result.setState(ContextStateEnum.SUCCESS);
      result.isSuccess();
      result.setData(Exist.getStr("conflict_id"));
      result.setMessage("创建成功");
      return result;
    }else{
      result.setState(ContextStateEnum.FAIL);
      result.isFail();
      result.setMessage("创建失败");
      return result;
    }

  }


  /**
  * @MethodName: saveExampleMenu
  * @Description: 保存生命周期菜单
  * @param: model
   * @param: exampleName
   * @param: exampleCode
   * @param: loginUser
  * @return * @return rapid.core.TResult
  * @throws
  * @date 2023/8/31 15:50
  * @author wj
  */
  public TResult saveExampleMenu(TsMenu model,String exampleName,String exampleCode, Authuser loginUser) {
    Record isExist = Db.findFirst("select id from ts_menu \n" +
                                    " where menu_code =? ", exampleCode);
    if(null== isExist){
      List<Record> records = Db.find(" select max(a.code) mcode,max(a.sort_id) sortid,b.code pcode from ts_menu a\n" +
                                       "left join ts_menu b on \n" +
                                       "a.pid = b.id where a.pid=?  group by b.code", model.getPid());
      TsMenu _top_menu = TsMenu.dao.findFirst("select * from ts_menu where id=?", model.getPid());

      if(_top_menu == null) {
        return TResult.fail("生命周期表单首级菜单不存在！");
      }

      int _mcode = 1;
      int _sortid = 1;
      String code="";
      if(records.size() > 0) {
          _mcode = Integer.parseInt(records.get(0).getStr("mcode")) + 1;
          _sortid = Integer.parseInt(records.get(0).getStr("sortid")) + 1;
      }else{
          code = _top_menu.getCode() + "01";
          _sortid = 0;
      }
      int sort = _sortid;
      if(StrKit.isBlank(code)) {
          code = Integer.toString(_mcode);
      }
      model.setCode(code);
      model.setSortId(sort);
      model.setVisible(WhetherEnumCls.YES.getValue());
      model.setEnabled(WhetherEnumCls.YES.getValue());
      model.setType("2");
      model.setName(exampleName);
      model.setPath("/sysadmin/life?code="+exampleCode);
      model.setMenuType("LIFECYC");
      model.setMenuCode(exampleCode);
      if(model.save() != true) {
        return TResult.fail("保存失败！");
      }
      log(loginUser.getId(), loginUser.getName(), "生命周期/生命周期实例", "创建菜单", loginUser.getIp(), "非普通菜单编号：" + model.getMenuCode());
    }else {
      return TResult.fail("创建菜单失败，非普通菜单编号已存在！");
    }
    return success();
  }

  /**
  * @MethodName: getLifecycModelNode
  * @Description: 获取生命周期模型节点
  * @param: modelName
   * @param: rowId
  * @return * @return java.util.List<com.jfinal.plugin.activerecord.Record>
  * @throws
  * @date 2023/8/31 15:50
  * @author wj
  */
  public List<Record> getLifecycModelNode(String modelName,String rowId) {
    StringBuilder _strSql = new StringBuilder();
    StringBuilder _strWhere = new StringBuilder();
    _strSql.append(String.format("select conflict_id,attrib_01 from s_lifecyc_model_node where row_id = '%s' ",rowId));
    if(StrKit.notBlank(modelName)) {
      _strWhere.append(Helper.getVagueQuery(modelName, " attrib_01 ", true));
    }
    List<Record> _returnData = new ArrayList<Record>();
    String resultSql = _strSql.toString() + _strWhere.toString() + " and limit 20  ";
    _returnData = Db.find(resultSql);
    return _returnData;
  }

  /**
  * @MethodName: getLifecycModelNodeById
  * @Description: 获取生命周期模型节点根据id
  * @param: conflictId
  * @return * @return net.yxsoft.model.SLifecycModelNode
  * @throws
  * @date 2023/8/31 15:50
  * @author wj
  */
  public SLifecycModelNode getLifecycModelNodeById(String conflictId) {
    return modelNodeDao.findById(conflictId);
  }

  /**
  * @MethodName: saveLifecycExampleNode
  * @Description: 保存生命周期实例节点
  * @param: model
   * @param: loginUser
  * @return * @return rapid.core.TResult
  * @throws
  * @date 2023/8/31 15:50
  * @author wj
  */
  public TResult saveLifecycExampleNode(SLifecycExampleNode model, Authuser loginUser) {
    if(StrKit.notNull(loginUser)) {
      Date date = new Date(System.currentTimeMillis());
      String Logs = "";
      if(StrKit.isBlank(model.getConflictId())) {
        model.setConflictId(Helper.bulidUUID());
        model.setRowId(model.getRowId());
        model.setCreated(date);
        model.setCreatedBy(loginUser.getName());
        if(model.save() != true) {
          return TResult.fail("保存失败！");
        }
        Logs = "主键:" + model.getConflictId() ;
        log(loginUser.getId(), loginUser.getName(), "生命周期/生命周期实例节点", "新增", loginUser.getIp(), Logs);

      } else {
        SLifecycExampleNode exmapleNodeOject = exampleNodeDao.findById(model.getConflictId());
        Logs = "主键:" + exmapleNodeOject.getConflictId() + ";修改前有效截止日期："+exmapleNodeOject.getAttrib14() + ";修改后有效截止日期：" + model.getAttrib14();
        if(null != exmapleNodeOject) {
          exmapleNodeOject.setLastUpd(date);
          exmapleNodeOject.setLastUpdBy(loginUser.getName());
          exmapleNodeOject.setAttrib14(model.getAttrib14());
          exmapleNodeOject.setAttrib20(model.getAttrib20());
          exmapleNodeOject.setAttrib21(model.getAttrib21());
          if(exmapleNodeOject.update() != true) {
            return TResult.fail("编辑失败！");
          }
          log(loginUser.getId(), loginUser.getName(), "生命周期/生命周期实例节点", "编辑", loginUser.getIp(), Logs);


        } else {
          return TResult.fail("您编辑的数据不存在或已被删除！");
        }
      }
    } else {
      return TResult.fail("未获得用户信息,请重新登录！");
    }
    return success();
  }

  /**
  * @MethodName: getUserType
  * @Description:
  * @param:
  * @return * @return java.util.List<net.yxsoft.model.infrastructure.TsCode>
  * @throws
  * @date 2023/8/31 15:50
  * @author wj
  */
  public List<TsCode> getUserType() {
    return codeDao.find("select codename,customid from ts_code where codetype='EXAMPLEUSERTYPE' and leaf ='2' and enabled ='1' ");
  }
  /**
  * @MethodName: getUsers
  * @Description:
  * @param: userName
  * @return * @return java.util.List<com.jfinal.plugin.activerecord.Record>
  * @throws
  * @date 2023/8/31 15:51
  * @author wj
  */
  public List<Record> getUsers(String userName) {
    StringBuilder _strSql = new StringBuilder();
    StringBuilder _strWhere = new StringBuilder();
    _strSql.append("select t1.id ,t1.name from ts_user t1 where  t1.name is not null  ");
    if(StrKit.notBlank(userName)) {
      _strWhere.append(Helper.getVagueQuery(userName, " t1.name ", true));
    }
    List<Record> _returnData = new ArrayList<Record>();
  //  String resultSql = _strSql.toString() + _strWhere.toString() + " limit 20  ";
    String resultSql = _strSql.toString() + _strWhere.toString() ;
    _returnData = Db.find(resultSql);
    return _returnData;
  }
  /**
  * @MethodName: saveLifecycExamplePER
  * @Description:
  * @param: model
   * @param: loginUser
  * @return * @return rapid.core.TResult
  * @throws
  * @date 2023/8/31 15:51
  * @author wj
  */
  public TResult saveLifecycExamplePER(SLifecycExampleNodePer model, Authuser loginUser) {
    if(StrKit.notNull(loginUser)) {
      String Logs = "";
      if(StrKit.isBlank(model.getConflictId())) {
        String[] userIds = model.getAttrib01().split(",");
        List<String> _sqlList = new ArrayList<>();
        for(String str : userIds) {
          Record record = Db.findFirst(" select a.conflict_id,b.name from s_lifecyc_example_node_per a \n" +
                                       " left join ts_user b on a.attrib_01=b.id where a.attrib_01 =? and a.row_id =?",str,model.getRowId());
          if(null !=record){
            return TResult.fail("当前生命周期实例节点下已存在用户"+record.getStr("name")+"!");
          }
          String key = Helper.bulidUUID();
          _sqlList.add(String.format(" insert into s_lifecyc_example_node_per(conflict_id,row_id,attrib_01,attrib_02,created_by) " +
                                       " values('%s','%s','%s','%s','%s')", key, model.getRowId(), str, model.getAttrib02(), loginUser.getName()));
          Logs += "主键集合：" + key + ";";
        }
        Db.batch(_sqlList, 10000);
        log(loginUser.getId(), loginUser.getName(), "生命周期/生命周期实例节点参与人员", "新增", loginUser.getIp(), Logs);
      }else{
        SLifecycExampleNodePer exmapleNodePerOject = exampleNodePerDao.findById(model.getConflictId());
        Logs = "主键:" + exmapleNodePerOject.getConflictId() + ";修改前状态："+ exmapleNodePerOject.getAttrib02() + ";修改后状态："+model.getAttrib02() ;
        if(null != exmapleNodePerOject) {
          exmapleNodePerOject.setLastUpdBy(loginUser.getName());
//          exmapleNodePerOject.setAttrib01(model.getAttrib01());
          exmapleNodePerOject.setAttrib02(model.getAttrib02());
          if(exmapleNodePerOject.update() != true) {
            return TResult.fail("编辑失败！");
          }
          log(loginUser.getId(), loginUser.getName(), "生命周期/生命周期实例节点参与人员", "编辑", loginUser.getIp(), Logs);


        } else {
          return TResult.fail("您编辑的数据不存在或已被删除！");
        }
      }
    } else {
      return TResult.fail("未获得用户信息,请重新登录！");
    }
    return success();
  }
  /**
  * @MethodName: deleteExamplePER
  * @Description:
  * @param: Ids
   * @param: loginUser
  * @return * @return rapid.core.TResult
  * @throws
  * @date 2023/8/31 15:51
  * @author wj
  */
  public TResult deleteExamplePER(String[] Ids, Authuser loginUser) {
    List<String> _sqlList =new ArrayList<String>();
    for(String id:Ids) {
      _sqlList.add(String.format(" delete from s_lifecyc_example_node_per where conflict_id = '%s' ",id));
    }
    Db.batch(_sqlList, 10000);
    log(loginUser.getId(), loginUser.getName(), "生命周期/生命周期实例节点参与人员", "删除", loginUser.getIp(), StringUtils.join(Ids, ","));
    return success();
  }


  /**
  * @MethodName: getExampleMenus
  * @Description: 获取生命周期菜单
  * @param:
  * @return * @return java.util.List<com.jfinal.plugin.activerecord.Record>
  * @throws
  * @date 2023/8/31 15:51
  * @author wj
  */
  public List<Record> getExampleMenus() {
    StringBuilder _strSql = new StringBuilder();
    _strSql.append("select * from ts_menu where menu_type='LIFECYC' and type='1' and pid=0 and enabled='1' order by sort_id desc");
    List<Record> _returnData = new ArrayList<Record>();
    String resultSql = _strSql.toString();
    _returnData = Db.find(resultSql);
    return _returnData;
  }
  /**
  * @MethodName: getLifecycExampleNodePer
  * @Description:
  * @param: nodeId
   * @param: user
  * @return * @return net.yxsoft.model.SLifecycExampleNodePer
  * @throws
  * @date 2023/8/31 15:51
  * @author wj
  */
  public SLifecycExampleNodePer getLifecycExampleNodePer(String nodeId,Authuser user){
    return SLifecycExampleNodePer.dao.findFirst("select A.* from S_LIFECYC_EXAMPLE_NODE_PER a\n" +
                                                  " left join TS_USER c on a.ATTRIB_01 = C.id \n" +
                                                  "where A.ROW_ID=? and C.ID=?",nodeId,user.getId());
  }


  /**
  * @MethodName: getMeetType
  * @Description: 获取会议类型
  * @param:
  * @return * @return java.util.List<net.yxsoft.model.infrastructure.TsCode>
  * @throws
  * @date 2023/8/31 15:51
  * @author wj
  */
  public List<TsCode> getMeetType(){
    List<TsCode> codeList = new TsCode().dao().find("select customid,codename from TS_CODE where leaf = 2 and codetype = 'hy'");
    return  codeList;
  }


  /**
  * @MethodName: getEnterpriseName
  * @Description: 获取企业名称
  * @param: model
  * @return * @return java.util.List<com.jfinal.plugin.activerecord.Record>
  * @throws
  * @date 2023/8/31 15:52
  * @author wj
  */
  public List<Record> getEnterpriseName(String model){
    StringBuilder _strSql = new StringBuilder();
    StringBuilder _strWhere = new StringBuilder();
    _strSql.append("select fd.attrib_06 enterprise_name,fd.conflict_id from FN_FORM_DATA fd\n" +
                     "LEFT JOIN FN_FORM ff on fd.attrib_01 = ff.id\n" +
                     "where ff.code = 'dj'");
    if(StrKit.notBlank(model)) {
      _strWhere.append(Helper.getVagueQuery(model, " fd.attrib_06 ", true));
    }
    List<Record> _returnData = new ArrayList<Record>();
    String resultSql = _strSql.toString() + _strWhere;
    _returnData = Db.find(resultSql);
    return _returnData;
  }



  /**
  * @MethodName: getTabname
  * @Description: 获取关联生命周期节点标签
  * @param: orgname
  * @return * @return java.util.List<net.yxsoft.model.infrastructure.TsCode>
  * @throws
  * @date 2023/8/31 15:52
  * @author wj
  */
  public List<TsCode> getTabname(String orgname){
    List<TsCode> list = new ArrayList<TsCode>();
    StringBuilder _strSql = new StringBuilder();
    _strSql.append(" select codename name,codename id from TS_CODE where CODETYPE = '生命周期标签' and LEAF = '2' order by sortno");
    if(rapid.util.StrKit.notBlank(orgname)) {
      _strSql.append(Helper.getVagueQuery(orgname, "codename", true));
    }
    list = new TsCode().dao.find(_strSql.toString());
    return list;
  }

}
